//////////////////////////////////////////////////////////////////////
//
//	Copyright 2010-2011 Rogo's Team. All Rights Reserved
//
//////////////////////////////////////////////////////////////////////
package com.rogo.mvc.core
{
	import com.rogo.mvc.interfaces.IModel;
	import com.rogo.mvc.interfaces.IProxy;
	
	import flash.utils.Dictionary;
	
	public class Model implements IModel
	{
		private static var instance:IModel;
		private var proxyMap:Dictionary;
		
		public function Model()
		{
			super();
			init();
		}
		
		public static function getInstance():IModel
		{
			if (!instance) instance = new Model();
			return instance;
		}
		
		private function init():void
		{
			proxyMap = new Dictionary();
		}
		
		public function registerProxy(proxy:IProxy):void
		{
			proxyMap[proxy.proxyName] = proxy;
			proxy.onRegister();
		}
		
		public function retrieveProxy(proxyName:String):IProxy
		{
			return proxyMap[proxyName];
		}
		
		public function removeProxy(proxyName:String):IProxy
		{
			var proxy:IProxy = proxyMap[proxyName];
			if (proxy)
			{
				delete proxyMap[proxyName];
				proxy.onRemove();
			}
			return proxy;
		}
		
		public function hasProxy(proxyName:String):Boolean
		{
			return proxyMap[proxyName];
		}
	}
}